package com.example.baseapp.service.impl;

import com.example.baseapp.entity.Breakfast;
import com.example.baseapp.repository.BreakfastRepository;
import com.example.baseapp.service.BreakfastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
public class BreakfastServiceImpl implements BreakfastService {
    @Autowired
    private BreakfastRepository breakfastRepository;

    @Override
    public Breakfast save(Breakfast breakfast) {
        breakfast.setCreateTime(LocalDateTime.now());
        breakfast.setUpdateTime(LocalDateTime.now());
        return breakfastRepository.save(breakfast);
    }

    @Override
    public List<Breakfast> findAll() {
        return breakfastRepository.findAll();
    }

    @Override
    public Breakfast findById(Long id) {
        Optional<Breakfast> optional = breakfastRepository.findById(id);
        return optional.orElse(null);
    }

    @Override
    public void deleteById(Long id) {
        breakfastRepository.deleteById(id);
    }

    @Override
    public Breakfast update(Breakfast breakfast) {
        breakfast.setUpdateTime(LocalDateTime.now());
        return breakfastRepository.save(breakfast);
    }
} 